package ${serviceClazz?lower_case}.dto;

import org.apache.commons.lang3.StringUtils;

import java.util.Date;
import lombok.Data;
import lombok.EqualsAndHashCode;
import com.system.core.view.layui.table.TableViewReqDto;

import io.swagger.v3.oas.annotations.media.Schema;

@Data
@EqualsAndHashCode(callSuper = true)
@Schema(description = "${tableInfo.tableComment}查询DTO")
public class ${serviceName?cap_first}QueryFilter extends TableViewReqDto{

	<#list columns as item>
	//${item.columnRemark}
	@Schema(description = "${item.columnRemark}"<#if (!item.nullAble)>,requiredMode = Schema.RequiredMode.REQUIRED</#if>)
	private ${item.javaType} ${item.javaCode};
	</#list>
	<#list columns as item>
	<#if (item.columnType?index_of('timestamp') >= 0) || (item.columnType?index_of('datetime') >= 0)>
	/**
	 * ${item.columnRemark}
	 * jdbctype:${item.columnType}
	 */
	private String ${item.javaCode}${TIMESTARTSTR};
	private String ${item.javaCode}${TIMEENDSTR};
	
	</#if>
	</#list>

	public String toQueryString() {
		StringBuilder param = new StringBuilder();
		<#list columns as item>
		<#if (item.columnType?index_of('varchar') >= 0) 
			|| (item.columnType?index_of('text') >= 0)>
		/**
		 * ${item.columnRemark}
		 * jdbcType:${item.columnType}
		 */
		if(StringUtils.isNotBlank(get${item.javaCode?cap_first}())) {
			param.append("&${item.javaCode}=");
			param.append(get${item.javaCode?cap_first}());
		}
		</#if>
		<#if (item.columnType?index_of('int') >= 0)
			||(item.columnType?index_of('decimal') >= 0)
			|| (item.columnType?index_of('enum') >= 0)>
		/**
		 * ${item.columnRemark}
		 * jdbcType:${item.columnType}
		 */
		if(get${item.javaCode?cap_first}() != null) {
			param.append("&${item.javaCode}=");
			param.append(get${item.javaCode?cap_first}());
		}
		</#if>
		<#if (item.columnType?index_of('timestamp') >= 0) || (item.columnType?index_of('datetime') >= 0)>
		/**
		 * ${item.columnRemark}
		 * jdbcType:${item.columnType}
		 */
		if(StringUtils.isNotBlank(get${item.javaCode?cap_first}${TIMESTARTSTR}())) {
			param.append("&${item.javaCode}${TIMESTARTSTR}=");
			param.append(get${item.javaCode?cap_first}${TIMESTARTSTR}());
		}
		if(StringUtils.isNotBlank(get${item.javaCode?cap_first}${TIMEENDSTR}())) {
			param.append("&${item.javaCode}${TIMEENDSTR}=");
			param.append(get${item.javaCode?cap_first}${TIMEENDSTR}());
		}
		</#if>
		</#list>
//		if(param.length() > 0)
//			return "?"+param.toString().substring(1, param.length());
//		else
		return param.toString();
	}
	
	@Override
	public String toString() {
		return toQueryString();
	}
}
